﻿using AutoMapper;
using MediatR;
using MyMES.Domain.zmc;
using MyMES.Error;
using MyMES.Infrastructure.Interface;
using MyMES.Writer.API.Application.Commends.Incominginformations;

namespace MyMES.Writer.API.Application.CommendHandlers.Incominginformations
{
    public class CreateIncominginformationsCommendHandlers : IRequestHandler<CreateIncominginformationsCommends, APIResult<Incominginformation>>
    {

        private readonly IBaseRepository<Incominginformation> baseRepository;
        private readonly IMapper mapper;

        public CreateIncominginformationsCommendHandlers(IBaseRepository<Incominginformation> baseRepository, IMapper mapper)
        {
            this.baseRepository = baseRepository;
            this.mapper = mapper;
        }

        /// <summary>
        /// 创建入库信息
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<APIResult<Incominginformation>> Handle(CreateIncominginformationsCommends request, CancellationToken cancellationToken)
        {
            APIResult<Incominginformation> result = new APIResult<Incominginformation>();
            result.Code = APIEnum.添加成功;
            result.Msg = "添加成功";

       
            var sql = "INSERT INTO incominginformation(StorageNo,StorageName,noticeId,SupplierId,Storageremark,StoragePurchaseId,StorageDate,NoticePurchase,IsDlete) VALUES(@StorageNo,@StorageName,@noticeId,@SupplierId,@Storageremark,@StoragePurchaseId,@StorageDate,@NoticePurchase,@IsDlete)";
            var enter = mapper.Map<Incominginformation>(request);
            await baseRepository.Insert(enter, sql);
            return result;
        }
    }
}
